<?php
namespace Shoptaemob\Controller;
use Think\Controller;
class IndexController extends ExtendController {
	public function index(){
		$params = Array(
					"m"=>"shopmobile",
					"c"=>"index",
					"a"=>"ajax_index",
					"sid"=>$this->sid,
					"tida_mixnick"=>$this->mixednick
				  );
		$data = json_decode($this->http(C("TAE_URL"),$params),true);
		// $data = json_decode($this->http("http://llxlw.hz.taeapp.com/",$params),true);
		// https://choujiang.shopmodule.jaeapp.com/
		// https://choujiang-1.shopmodule.jaeapp.com/
		if(!$data["event"]){
			$this->assign("msg","当前时间没有活动！");
			$this->display("Shopmobile@Index:not_allow");
			die();	
		}		
		if(!in_array($data["display"],C("SUPPORT_MOB"))){
			$this->assign("msg","抱歉，不支持当前的模板哦！");
			$this->display("Shopmobile@Index:not_allow");
			die();	
		}
		$this->assign("tae_url",C("TAE_URL"));
		$this->assign("assets","shoptaemob");
		$this->assign("seller_nick",$data["seller_nick"]);
		$this->assign("getway",$data["getway"]);
		$this->assign("user",$data["user"]);
		$this->assign("event",$data["event"]);
		$this->assign("cfg",$data["event"]);
		$this->assign("gifts",$data["gifts"]);
		$this->assign("mygifts",$data["mygifts"]);
		$this->assign("prizeList",$data["prizeList"]);
		$this->display("Shopmobile@".$data["display"]);
	}
	public function taepc_friendshow(){
		//PC端的分享转移到移动端操作
		$data["sid"]=I("sid");
		$data["shop_uid"]=I("shop_uid");
		$data["gid"]=I("gid");
		$data["mygid"]=I("mygid");
		$data["getway"]=I("getway");
		$data["pic_url"]=I("pic_url");
		$data["show_title"]=I("show_title");
		$data["show_content"]=I("show_content");
		$data["show_title"]=$data["show_title"]?$data["show_title"]:"我中奖啦！";
		$data["show_content"]=$data["show_content"]?$data["show_content"]:"亲，我中奖啦！快来和我一起抽奖哦！";
		$data["show_url"]=C("URL")."?c=shoptaemob&sid=".$sid;
		$data["json"]=json_encode($data);
		
		$this->assign("TAE_URL",C("TAE_URL"));
		$this->assign("data",$data);
		$this->display();
	}
	public function http($url, $params, $method = 'GET', $header = array(), $multi = false){
		$opts = array(
				CURLOPT_TIMEOUT        => 30,
				CURLOPT_RETURNTRANSFER => 1,
				CURLOPT_SSL_VERIFYPEER => false,
				CURLOPT_SSL_VERIFYHOST => false,
				CURLOPT_HTTPHEADER     => $header
		);
		/* 根据请求类型设置特定参数 */
		switch(strtoupper($method)){
			case 'GET':
				$opts[CURLOPT_URL] = $url . '?' . http_build_query($params);
				break;
			case 'POST':
				//判断是否传输文件
				$params = $multi ? $params : http_build_query($params);
				$opts[CURLOPT_URL] = $url;
				$opts[CURLOPT_POST] = 1;
				$opts[CURLOPT_POSTFIELDS] = $params;
				break;
			default:
				throw new \Exception('不支持的请求方式！');
		}
		/* 初始化并执行curl请求 */
		$ch = curl_init();
		curl_setopt_array($ch, $opts);
		$data  = curl_exec($ch);
		$error = curl_error($ch);
		curl_close($ch);
		if($error) throw new \Exception('请求发生错误：' . $error);
		return  $data;
	}

}